
<?php include 'header.php';?>
    <div style="overflow:hidden;font-size: 12px;border:0;background:#ede7f6;padding:10px 20px;" class="section">
        <span class="left" style="color: #333;" id="totalbook"></span>
    </div>
    <!--其他区域-->
    <section id="likelist">
        <?php
            if( count($result) == 0 ){
                echo '<div style="font-size:20px;width:100%;padding-top:30px;text-align:center;">';
                echo '    〒_〒,还什么都没收藏呢';
                echo '</div>';
            }else{
                foreach( $result as $key => $val ){
                    echo '<a href="/detail?href='.$val['href'].'" class="block item"  listid="'.$val['mac_no'].'">';
                    echo '    <img src="'.$val['pic'].'" />';
                    echo '<h3>';
                    $temp_title = str_replace('<a', '<span', $val['title']);
                    $temp_title = str_replace('</a', '</span', $temp_title);
                    echo $temp_title;
                    echo '</h3>';
                    echo '    <div style="word-wrap:break-word;word-break:break-all;">';
                    echo '        <span style="font-size:14px;" class="mcolor">摘要：</span>';
                    echo $val['brief'];
                    echo '    </div>';
                    echo '    <div>';
                    echo '        <hr>';
                    echo '        <span class="no-button" style="font-size:12px;display:inline-block">';
                    $temp_time_arr = explode(' ', $val['add_time']);
                    echo '            收藏时间：'.$temp_time_arr[0];
                    echo '        </span> ';
                    echo '        <span class="no-button right unlike" mac_no ="'.$val['mac_no'].'" style="font-size:12px;display:inline-block"" onclick="event.preventDefault();">';
                    echo '             <i class="icon iconfont icon-close" style="font-size:12px;"></i>取消收藏';
                    echo '        </span> ';
                    echo '    </div>';
                    echo '</a> ';
                }
            }
        ?>
    </section>
<?php include 'footer.php';?>
<script type="text/javascript">
    $("h3").attr("src","javascript:void(0);");
    $("#topbar").html('<a href="/center" style="color:#fff;"><h1><i class="icon iconfont icon-left" style="margin-right:4px;"></i>藏经阁</h1></a>');
    $("#totalbook").html("共收藏图书<span id='likenum'><?php echo $count; ?></span>本");
    $(".unlike").on("click",function(){
        var mac_no = $(this).attr("mac_no");
        if (mac_no==0) {toast("粗错啦~~~T T");return;};
        if (user_id==0) {location.href="/ptime/login?return_url="+window.location.href;return;};
        $("#loading").show();
        $.ajax({
            type:"post",
            url:"/api/book/collect",
            data:{"user_id":user_id,"mac_no":mac_no,"is_cancel":1},
            dataType:"json",//text/xml/json，非必须
            success:function(data){//回调函数，非必须
                if (!data.error) {
                    $("#likelist a").each(function(){
                        console.log($(this).attr('listid'));
                        console.log(mac_no);
                        if ($(this).attr('listid')*1==mac_no*1) {
                            $(this).remove();
                        };
                    })
                    $("#loading").hide();
                    $("#likenum").html($("#likenum").html()*1-1);
                    toast("已取消收藏~");
                }else{
                    toast(data.message);
                };
            }
        });         
    })
    $(window).scroll(function () {
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
        console.log(scrollTop + windowHeight ==  scrollHeight);
        if (scrollTop + windowHeight ==  scrollHeight) {
            toast("木有更多啦~");
        }
    });
</script>